package com.liudw.eureka.ribbon.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@RestController
public class UserController {

	@Value("${server.port}")
	private String port;
	
	@Autowired
	private RestTemplate restTemplate;
	
	@HystrixCommand(fallbackMethod = "fallback")
	@RequestMapping(value = "hi", method = RequestMethod.GET)
	public String hi(String message) {
		return restTemplate.getForObject("http://eureka-client/user/hi?message="+message, String.class);
	}
	
	public String fallback(String message) {
		return String.format("%s, 快速失败，现在port是:%s", message, port);
	}
}
